#ifndef __SYS_RADAR_DEF_H__
#define __SYS_RADAR_DEF_H__


#include <stdint.h>

#define MAX_WIN_RANGE          (256) // chebwin
#define MAX_WIN_VEL            (256) // hanning
#define NUM_ANGLE              (64)
#define ANT_MAX_NUM            (2)

/*
 * PC 相关定义
*/
 typedef struct
 {
 	uint16_t d1Idx;   //Range idx
 	uint8_t d2Idx;    //Vel idx
 	uint8_t d3Idx;    //Horizontal angle idx
 	uint32_t powABS;  //Pow abs
 }STRUCT_TARGETPOINT;

 #define STRUCT_POINTRST_DEF \
 struct{\
	uint16_t targetNum;\
	uint16_t deltaT;\
	uint32_t targetMax;\
	STRUCT_TARGETPOINT* target;\
 }
 
 struct pc_rst{
	 STRUCT_POINTRST_DEF;
 };

/*
 * EPC 相关定义
 */
#define STRUCT_DEF \
struct{ \
uint32_t  pow;\
uint32_t  rIdx;\
int32_t   vIdx;\
int32_t   sinPhiIdx;\
uint32_t  presence_flag;\
uint8_t   info1;\
uint8_t   info2;\
}

typedef STRUCT_DEF epc_unit_t;
struct epc_target{
	STRUCT_DEF;
	uint16_t unprocess_flag;
};


#define STRUCT_EPC_DEF \
struct{\
	uint16_t frame_interval;\
	uint16_t target_cnt;\
	uint16_t range_res_mm;  \
	int16_t  vel_res_mm_s; \
	uint16_t rangeMax;\
	uint8_t  chirpMax;\
	uint8_t  angleMax;\
	uint32_t  targetMax;\
	struct{\
		uint32_t rsv:16;\
		uint32_t range_offset_mm:12;\
		uint32_t res_decimals:4;\
	}addon;\
	struct epc_target* p_target;\
}

struct epc
{
	STRUCT_EPC_DEF;
};

/* 
 * alpha filter 相关定义
*/
struct alpha_target{
		STRUCT_DEF;
		uint16_t unprocess_flag;
		uint32_t sn_rcd;
		uint32_t update_cnt;
		uint32_t tick_start;
};

struct alpha_filter_cfg{
	uint32_t FILTER_RTH;
	uint32_t FILTER_VTH;
	uint32_t FILTER_ATH;
	uint8_t  FILTER_VALID_CNT;
	int8_t  EX_FACTOR_RV;
	int8_t  EX_FACTOR_A;
	
	int8_t  ALPHA_R;
	int8_t  ALPHA_V;
	int8_t  ALPHA_A;
	int8_t  FILTER_TIMEOUT_CNT;
	
	uint8_t  UPDATE_MODE;
};

struct alpha_target_ordered{
	uint32_t tick;
	int index;
};

#define ALPHA_FILTER_DEF \
struct{ \
	uint16_t cnt;\
	uint16_t color_sn;\
	uint32_t filter_num_max;\
	struct alpha_target *p_target;\
	struct alpha_target_ordered *p_ordered;\
}

struct alpha_filter{
	ALPHA_FILTER_DEF;
};

/* 
 * dbscan 相关定义
*/
typedef struct {
		int16_t rIdx;
		int8_t vIdx;
		int8_t sinPhiIdx;
		uint8_t visited;
		uint8_t corePt;
		int8_t  clusterID;
	uint32_t abs;
} DBSCANPT;


#define DBSCANFRAME_DEF        \
struct {   \
		uint8_t ptNum; \
		DBSCANPT *pt;  \
}

typedef DBSCANFRAME_DEF DBSCANFRAME;

typedef struct {
		uint8_t epsRIdx;
		uint8_t epsVIdx;
		uint8_t epsSinPhiIdx;
		uint8_t minPts;
		uint16_t maxPts;
} DBSCANCFG;

typedef struct {
		int32_t rIdxMean;
		int32_t vIdxMean;
		int32_t sinPhiIdxMean;
		uint32_t abs;
} clusterRpt;

#define DBSCANOUT_DEF \
struct { \
		uint8_t numCluster; \
		clusterRpt *cluster; \
}
typedef DBSCANOUT_DEF DBSCANOUT;

#define DBSCANNB_DEF \
struct{ \
		uint8_t ptNum;\
		uint8_t *idx;\
}
typedef DBSCANNB_DEF DBSCANNB;

struct dbscan_cluster{
	DBSCANFRAME  * dbscanFrame;
	DBSCANOUT    * dbscanClu;
	DBSCANNB     * nbA;
	DBSCANNB     * nbB;
	DBSCANCFG    * cfg;
	uint16_t     cluster_max_num;
	uint16_t     frame_max_num;
};



#endif
